package com.wmh.baseservice.admin.pojo.vo.menu;

import com.wmh.baseservice.admin.entity.AdMenu;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author 谢骏
 * @date 2023/8/9 14:44
 **/
@ApiModel("添加和修改请求的基础字段")
@Data
@Accessors(chain = true)
public class AddAndUpdateReqFields {


    @NotNull(message = "未提交父级主键")
    private Long parentId;

    @NotBlank(message = "未提交名称")
    private String name;

    @NotNull(message = "未提交菜单类型")
    private Integer flag;

    private String permissions;

    private String requestUrl;

    private String component;

    private String menuIcon;

    private Integer sort;

    private Boolean keepAlive;


    public static AdMenu buildEntity(Long id, AddAndUpdateReqFields req){
        AdMenu adMenu = new AdMenu();
        adMenu.setId(id);
        adMenu.setMenuName(req.getName());
        adMenu.setPermissions(req.getPermissions());
        adMenu.setRequestUrl(req.getRequestUrl());
        adMenu.setMenuIcon(req.getMenuIcon());
        adMenu.setParentId(req.getParentId());
        adMenu.setComponent(req.getComponent());
        adMenu.setFlag(req.getFlag());
        adMenu.setSort(req.getSort());
        adMenu.setKeepAlive(req.getKeepAlive());
        adMenu.setUpdateTime(null);
        return adMenu;
    }
}
